package com.iqiyi.game.ams.ui.controller;

import com.iqiyi.game.ams.application.ActivityAppService;
import com.iqiyi.game.ams.ui.dto.ActivityDTO;
import com.iqiyi.game.ams.ui.dto.ResponseDTO;
import com.iqiyi.game.ams.ui.query.ActivityQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * @author hanbaoyu
 */
@RestController
@RequestMapping("activity")
public class ActivityController extends BaseController {

    @Autowired
    private ActivityAppService activityAppService;

    @GetMapping("")
    public ResponseDTO get(@Valid ActivityQuery activityQuery, BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            return error(bindingResult.getFieldError().getDefaultMessage());
        }

        ActivityDTO activityDTO = activityAppService.get(activityQuery);
        return success(activityDTO);
    }
}
